# uncompyle6 version 3.2.3
# Python bytecode 3.6 (3379)
# Decompiled from: Python 3.6.8 |Anaconda custom (64-bit)| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
# Embedded file name: helpers\mailer\renderer\filters.py
import datetime
from email.utils import formatdate


def flt_datetime(value, date_format="iso"):
    if date_format == "iso":
        return value.isoformat()
    elif date_format == "RFC3339":
        if value.tzinfo is None:
            suffix = "-00:00"
        else:
            suffix = value.strftime("%z")
            suffix = suffix[:-2] + ":" + suffix[-2:]
        return value.strftime("%Y-%m-%dT%H:%M:%S") + suffix
    elif date_format == "RFC3339M":
        if value.tzinfo is None:
            suffix = "-00:00"
        else:
            suffix = value.strftime("%z")
            suffix = suffix[:-2] + ":" + suffix[-2:]
        return value.strftime("%Y-%m-%dT%H:%M") + suffix
    elif date_format == "PPRINT":
        if value.tzinfo is None:
            suffix = "-00:00"
        else:
            suffix = value.strftime("%z")
            suffix = suffix[:-2] + ":" + suffix[-2:]
        return value.strftime("%b %d,%Y %H:%M:%S ") + suffix
    elif date_format == "PPRINT_UTC":
        if value.tzinfo is None:
            suffix = ""
        else:
            suffix = value.strftime("%z")
            if suffix in ("+0000", "-0000"):
                suffix = ""
            else:
                suffix = suffix[:-2] + ":" + suffix[-2:]
        return value.strftime("%b %d,%Y %H:%M:%S ") + suffix
    elif date_format == "RFC2822":
        return formatdate(value.timestamp(), value.timetz())
    else:
        return str(value)
